﻿@model StudentEditViewModel

@{
    ViewData["Title"] = "编辑学生信息";
    // 获取当前学生头像文件的完整路径
    var photoPath = "~/img/avatar/noimage.png";
    if (@Model.ExistingPhotoPath != null)
    {
        photoPath = "~/img/avatar/" + Model.ExistingPhotoPath;
    }
}

<form asp-controller="home" asp-action="edit"
      method="post" enctype="multipart/form-data" class="mt-3">
    <div asp-validation-summary="All" class="text-danger"></div>
    <input type="hidden" asp-for="Id" />
    <input type="hidden" asp-for="ExistingPhotoPath" />
    <div class="form-group row">
        <label asp-for="Name" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="Name" class="form-control" placeholder="请输入你的名字" />
            <span asp-validation-for="Name" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="Email" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="Email" class="form-control" placeholder="请输入你的邮箱" />
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="Marjor" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <select asp-for="Marjor" class="custom-select mr-sm-2"
                    asp-items="Html.GetEnumSelectList<MajorEnum>()">
                <option value="">-------请选择------</option>
            </select>
            <span asp-validation-for="Marjor" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="EnrollmentDate" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="EnrollmentDate" type="date" class="form-control" placeholder="选择时间" />
            <span asp-validation-for="EnrollmentDate" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="Phones" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <div class="custom-file">
                <input asp-for="Phones" multiple class="form-control custom-file-input" />
                <label class="custom-file-label">单击修改图片</label>
            </div>
        </div>
    </div>

    <div class="form-group row col-sm-4 offset-4">
        <img class="img-thumbnail" src="@photoPath" asp-append-version="true" />
    </div>

    <div class="form-group row">
        <div class="col-sm-10">
            <button type="submit" class="btn btn-primary">更新</button>
            <a asp-action="index" asp-controller="home" class="btn btn-primary">
                取消
            </a>
        </div>
    </div>
</form>

@section Scripts {
    <script>
        $(document).ready(function () {
            $(".custom-file-input").on("change", function () {
                var fileLabel = $(this).next('custom-file-label');
                var files = $(this)[0].files;
                if (files.length > 1) {
                    fileLabel.html('你选择了：' + files.length + '个文件')
                } else if (files.length == 1) {
                    fileLabel.html(files[0].name)
                }
            });
        })
    </script>

    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

@*<div class="row">
        <div class="col-md-4">
            <form asp-action="Edit">
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                <div class="form-group">
                    <label asp-for="Id" class="control-label"></label>
                    <input asp-for="Id" class="form-control" />
                    <span asp-validation-for="Id" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="ExistingPhotoPath" class="control-label"></label>
                    <input asp-for="ExistingPhotoPath" class="form-control" />
                    <span asp-validation-for="ExistingPhotoPath" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="Name" class="control-label"></label>
                    <input asp-for="Name" class="form-control" />
                    <span asp-validation-for="Name" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="Marjor" class="control-label"></label>
                    <input asp-for="Marjor" class="form-control" />
                    <span asp-validation-for="Marjor" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="Email" class="control-label"></label>
                    <input asp-for="Email" class="form-control" />
                    <span asp-validation-for="Email" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <input type="submit" value="Save" class="btn btn-primary" />
                </div>
            </form>
        </div>
    </div>

    <div>
        <a asp-action="Index">Back to List</a>
    </div>

    @section Scripts {
        @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    }*@